<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class Tokens extends Model
{
    //
    protected $table = 'token';
    protected $fillable = ['token','user_id'];

    public static function refresh_token($user_id)
    {
        $token = create_token();
        $rel = Tokens::firstOrCreate(['user_id'=>$user_id],['user_id'=>$user_id,'token'=>$token]);

        return $rel->token;
    }

    public static function verify_token($token)
    {
        $rel = self::where(['token'=>$token])->first();
        return $rel;
    }
}
